blob: 18c72cdad1b310972a35dab0878c92af1bba75bf [file] [log] [blame]
Nicolás Peña Moreno84bcab62019-03-06 17:00:471<!DOCTYPE HTML>
2<meta charset=utf-8>
3<title>Element Timing: observe elements with the same resource</title>
4<body>
5<style>
6body {
7 margin: 0;
8}
9</style>
10<script src="/resources/testharness.js"></script>
11<script src="/resources/testharnessreport.js"></script>
12<script src="resources/element-timing-helpers.js"></script>
13<script>
14 let beforeRender;
15 let numEntries = 0;
16 let responseEnd1;
17 let responseEnd2;
18 const index = window.location.href.lastIndexOf('/');
19 const pathname = window.location.href.substring(0, index) +
20 '/resources/square100.png';
21 async_test(function (t) {
22 const observer = new PerformanceObserver(
23 t.step_func(function(entryList) {
24 entryList.getEntries().forEach(entry => {
25 checkElement(entry, pathname, entry.identifier, beforeRender);
26 if (entry.identifier === 'my_image') {
27 ++numEntries;
28 responseEnd1 = entry.responseEnd;
29 }
30 else if (entry.identifier === 'my_image2') {
31 ++numEntries;
32 responseEnd2 = entry.responseEnd;
33 }
34 });
35 if (numEntries == 2) {
36 assert_equals(responseEnd1, responseEnd2);
37 t.done();
38 }
39 })
40 );
41 observer.observe({entryTypes: ['element']});
42 // We add the images during onload to be sure that the observer is registered
43 // in time for it to observe the element timing.
44 window.onload = () => {
45 // Add image of width and height equal to 100.
46 const img = document.createElement('img');
47 img.src = 'resources/square100.png';
48 img.setAttribute('elementtiming', 'my_image');
49 document.body.appendChild(img);
50
51 const img2 = document.createElement('img');
52 img2.src = 'resources/square100.png';
53 img2.setAttribute('elementtiming', 'my_image2');
54 document.body.appendChild(img2);
55
56 beforeRender = performance.now();
57 };
58 }, 'Element with elementtiming attribute is observable.');
59</script>
60
61</body>